//
//  ZCThemeViewModel.m
//  BaiSi
//
//  Created by 张灿 on 16/5/2.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCThemeViewModel.h"
#import "ZCThemeItem.h"
#import "ZCCommentItem.h"

@implementation ZCThemeViewModel

- (void)setItem:(ZCThemeItem *)item
{
    _item = item;
    
    //计算topView的高度
    CGFloat margin = 10;
    CGFloat topX = 0;
    CGFloat topY = 0;
    CGFloat topW = ZCScreenW;
    CGFloat topH = 0;
    CGFloat miniH = 55;
    NSString *text = item.text;
    CGFloat textW = ZCScreenW - 2 * margin;
    
    CGFloat textH = [text sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
    topH = miniH + textH;
    
    _topFrame = CGRectMake(topX, topY, topW, topH);
    
    _cellH = CGRectGetMaxY(_topFrame) + margin + 10;
    
    //计算中间的frame
    if (item.type != ZCThemeTypeText && item.width) {
        CGFloat midX = margin;
        CGFloat midY = topH + margin;
        CGFloat midW = textW;
        CGFloat midH = textW / item.width * item.height;
        if (midH >= ZCScreenH) {
            //如果图片的高度大于屏幕高度,就让高度等于300
            midH = 300;
            item.is_bigPicture = YES;
        }
        _middleFrame = CGRectMake(midX, midY, midW, midH);
        _cellH = CGRectGetMaxY(_middleFrame) + margin + 10;
    }
    if (item.commentItem) {
        CGFloat hotX = margin;
        CGFloat hotY = _cellH;
        CGFloat hotW = textW;
        CGFloat hotH = 42; //默认42
        if (item.commentItem.content.length) {//文字评论时
            hotH = [item.commentItem.totalCotent sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height + 21;
        }
        _hotFrame = CGRectMake(hotX, hotY, hotW, hotH);
        _cellH = CGRectGetMaxY(_hotFrame) + margin + 10;
    }
    
    //计算底部Frame
    _bottomFrame = CGRectMake(0, _cellH, ZCScreenW, 35);
    _cellH = CGRectGetMaxY(_bottomFrame) + margin + 10;
    
    
}

@end
